package activity.video;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.text.TextUtils;
import android.view.View;
import android.view.WindowManager;
import android.widget.ImageView;

import com.hichip.campro.R;

import java.util.ArrayList;
import java.util.List;

import activity.video.adapter.VpVideoAdapter;
import base.HiActivity;
import bean.MyCamera;
import butterknife.BindView;
import common.HiDataValue;
import utils.HiTools;
/**
 * 录像回放界面  远程录像和本地录像
 * Created by lt on 2018\2\24 0024.
 */
public class VideoActivity extends HiActivity implements View.OnClickListener {
    private MyCamera mMyCamera;
    @BindView(R.id.tablayout) TabLayout tabLayout;
    @BindView(R.id.btn_return) ImageView btn_return;
    @BindView(R.id.viewPager) ViewPager viewPager;
    
    @Override
    protected int setLayoutId() {
        return R.layout.activity_video;
    }

    @Override
    protected void init(@Nullable Bundle savedInstanceState) {
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
        getIntentData();
        if( HiTools.cameraWhetherNull(mMyCamera,this)) return;
        initViewAndData();
        setListeners();

    }

    private void setListeners() {
        btn_return.setOnClickListener(this);
    }

    private void initViewAndData() {
        tabLayout.addTab(tabLayout.newTab().setText("远程录像"));
        tabLayout.addTab(tabLayout.newTab().setText("本地录像"));
        List<String> titles=new ArrayList<>();
        titles.add("远程录像");
        titles.add("本地录像");

        List<Fragment> fragments=new ArrayList<>();
        //fragments.add(new PlaybackOnlineFragment());
        fragments.add(new VideoLocalFragment());
        VpVideoAdapter adapter=new VpVideoAdapter(getSupportFragmentManager(),fragments,titles);
        viewPager.setAdapter(adapter);
        tabLayout.setupWithViewPager(viewPager);
    }

    private void getIntentData() {
        String uid=getIntent().getStringExtra(HiDataValue.EXTRAS_KEY_UID);
        if(TextUtils.isEmpty(uid)) finish();
        for(MyCamera camera:HiDataValue.CameraList){
            if(uid.equalsIgnoreCase(camera.getUid())){
                this.mMyCamera=camera;
                break;
            }
        }

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.btn_return:
                VideoActivity.this.finish();
                break;
        }
    }

    public MyCamera getmMyCamera(){
        return this.mMyCamera;
    }


}




